// 获取全局应用程序实例对象
const app = getApp()

// 创建页面实例对象
Page({
    /**
     * 页面的初始数据
     */
  data: {
    userInfo: {
      wechat: '',
      nickName: '对联春联大全',
      describe: '',
      avatarUrl: '../../images/qrcode.jpg'
    },
    appListInfo: [{
      icon: '../../images/huazhuang.png',
      text: '最火新娘化妆师',
      isunread: false,
      rightIcon: '../../images/arrowright.png'
    }, {
      icon: '../../images/king.png',
      text: '脑筋急转弯',
      isunread: false,
      rightIcon: '../../images/arrowright.png'
    }, {
      icon: '../../images/star-yellow.png',
      text: '美女明星图',
      isunread: false,
      rightIcon: '../../images/arrowright.png'
      }, {
        icon: '../../images/fire.png',
        text: '生活小窍门',
        isunread: false,
        rightIcon: '../../images/arrowright.png'
      }, {
        icon: '../../images/emotion.png',
        text: '魔性动态图',
        isunread: false,
        rightIcon: '../../images/arrowright.png'
      }, {
        icon: '../../images/lantern.png',
        text: '猜灯谜',
        isunread: false,
        rightIcon: '../../images/arrowright.png'
      }]
  },
  getUserInfo: function() {
    const that = this
    app.wechat.getUserInfo()
      .then(res => {
        that.setData({ userInfo: res.userInfo })
        }
      )
  },
  previewImage: function() {
    wx.previewImage({
      current: 'https://upload-images.jianshu.io/upload_images/3100736-b6ffc2074c1f64e3.jpg', // 当前显示图片的http链接
      urls: ['https://upload-images.jianshu.io/upload_images/3100736-b6ffc2074c1f64e3.jpg'] // 需要预览的图片http链接列表
    })
  },
  onLoad: function () {
    // let that = this;
    // 调用应用实例的方法获取全局数据
    // app.getUserInfo(function (userInfo) {
    //   //更新数据
    //   that.setData({
    //     userInfo: userInfo
    //   })
    // })
    // that.getUserInfo();
  },
    onShareAppMessage: function () {
        this.imageUrl = this.data.imageUrls[Math.floor(Math.random() * this.data.imageUrls.length)];
        return {
            title: '这么火的游戏，一起玩儿啊！！',
            // desc: '这么火的游戏，一起玩儿啊！',
            path: '/pages/index/index',
            imageUrl: ''
        }
    },
  itemtap(e) {
    let dataSet = e.target.dataset;
    let index = dataSet.index;
    console.log('index: ' + index);
    if(index == 0) {
      wx.navigateToMiniProgram({
        appId: 'wxcfaaed37f35260fc',
        path: 'pages/index/index',
        // extraData: {
        //   foo: 'bar'
        // },
        envVersion: 'release',
        success(res) {
          // 打开成功
        }
      })
    }
    if (index == 1) {
      wx.navigateToMiniProgram({
        appId: 'wxfe657d267bbfb8a4',
        path: 'pages/index/index',
        // extraData: {
        //   foo: 'bar'
        // },
        envVersion: 'release',
        success(res) {
          // 打开成功
        }
      })
    }
    if (index == 2) {
      wx.navigateToMiniProgram({
        appId: 'wx684e5da21e3a9366',
        path: 'pages/index/index',
        // extraData: {
        //   foo: 'bar'
        // },
        envVersion: 'release',
        success(res) {
          // 打开成功
        }
      })
    }
    if (index == 3) {
      wx.navigateToMiniProgram({
        appId: 'wx8fe3f7c2c7e3366e',
        path: 'pages/list/index',
        // extraData: {
        //   foo: 'bar'
        // },
        envVersion: 'release',
        success(res) {
          // 打开成功
        }
      })
    }
    if (index == 4) {
      wx.navigateToMiniProgram({
        appId: 'wx5e8c98dc5b9ea8df',
        path: 'pages/index/index',
        // extraData: {
        //   foo: 'bar'
        // },
        envVersion: 'release',
        success(res) {
          // 打开成功
        }
      })
    }
    if (index == 5) {
      wx.navigateToMiniProgram({
        appId: 'wx4d1bb5a2ff512c47',
        path: 'pages/index/index',
        // extraData: {
        //   foo: 'bar'
        // },
        envVersion: 'release',
        success(res) {
          // 打开成功
        }
      })
    }
  }
})
